{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "871c1ae1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "                <script type=\"application/javascript\" id=\"jupyter_black\">\n",
       "                (function() {\n",
       "                    if (window.IPython === undefined) {\n",
       "                        return\n",
       "                    }\n",
       "                    var msg = \"WARNING: it looks like you might have loaded \" +\n",
       "                        \"jupyter_black in a non-lab notebook with \" +\n",
       "                        \"`is_lab=True`. Please double check, and if \" +\n",
       "                        \"loading with `%load_ext` please review the README!\"\n",
       "                    console.log(msg)\n",
       "                    alert(msg)\n",
       "                })()\n",
       "                </script>\n",
       "                "
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%load_ext jupyter_black"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "21275a04",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9544074144996451\n"
     ]
    }
   ],
   "source": [
    "v1 = [0, 3, 4, 5, 6]\n",
    "v2 = [4, 5, 6, 7, 8]\n",
    "\n",
    "\n",
    "def dot(v1, v2):\n",
    "    dot_product = sum((a * b) for a, b in zip(v1, v2))\n",
    "    return dot_product\n",
    "\n",
    "\n",
    "def cosine_similarity(v1, v2):\n",
    "    \"\"\"\n",
    "    (v1 dot v2)/||v1|| *||v2||)\n",
    "    \"\"\"\n",
    "    products = dot(v1, v2)\n",
    "    denominator = (dot(v1, v1) ** 0.5) * (dot(v2, v2) ** 0.5)\n",
    "    similarity = products / denominator\n",
    "    return similarity\n",
    "\n",
    "\n",
    "print(cosine_similarity(v1, v2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "74f41cf3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.95440741]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.metrics import pairwise\n",
    "\n",
    "v1 = [0, 3, 4, 5, 6]\n",
    "v2 = [4, 5, 6, 7, 8]\n",
    "\n",
    "# need to be in numpy data format\n",
    "pairwise.cosine_similarity([v1], [v2])\n",
    "# array([[0.95440741]])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "embed",
   "language": "python",
   "name": "embed"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
